<template>
        <div class="search">
              <el-autocomplete
              v-model="searchKey"
              :fetch-suggestions="changeInput"
              :trigger-on-focus="false"
              width="100%"
              clearable
              class="inline-input w-50"
              placeholder="请输入医院名称"
              @select="handleSelect"
            />
            <el-button type="primary"><el-icon><Search /></el-icon></el-button>
        </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref , defineEmits}  from 'vue'
import { getHospitalByKeywordAPI} from '@/api/hospital'
import { useRouter } from 'vue-router'
const router = useRouter()
const emit = defineEmits(['onChange'])
const searchKey = ref('')
const changeInput = async(key, callback) => {
  // console.log(searchKey.value);
  const res = await getHospitalByKeywordAPI(searchKey.value)
  console.log(res);
  res.data.forEach(item => {
    item.value = item.hosname
  })
  callback(res.data)

}
const handleSelect = (item) => {
  // console.log(item.hoscode);
  router.push({path: `/hospital/register`, query: {hoscode: item.hoscode}})
}
</script>

<style lang="scss" scoped>
.search {
  width: 1200px;
  // background-color: pink;
  display: flex;
  justify-content: center;
  margin: 20px 0;
 
  :deep(.el-input__wrapper) {
    width: 600px;
    height: 40px;
  
  }
  .el-button {
    height: 40px;
    width: 60px;
  }

  }
</style>